/**
*百度的一个延时js方法
*里面的time按照自己的电脑性能和当前网速自己设置
*/
window.sleeptime = 200;
function sleepM()
{
	
	return new Promise((resolve) => setTimeout(resolve, window.sleeptime));
}
/**
 * 设置休眠时间
 */
function resetSleepM(sleeptime)
{
    let newsleeptime = sleeptime>0?sleeptime:200
    console.log("重新设置sleeptime，oldsleeptime="+window.sleeptime+",newsleeptime = "+newsleeptime);
    window.sleeptime = newsleeptime;
}
/*
*重新启动
 */
function start()
{    
    window.stopflag = false;
    let i = window.curi|0;
    let j = window.curj|0;
    let k = window.curk|0;
    let pb = window.curpb|0;
    let cb = window.curcb|0;
    delete(window.curi);
    delete(window.curj);
    delete(window.curk);
    delete(window.curpb);
    delete(window.curcb);
    console.log("重新开始执行i="+i+",j="+j+",k="+k+",pb="+pb+",cb="+cb);
    logLevel(i,j,k,pb,cb);
}
/**
*设置停止标识
*/
function stop()
{
    window.stopflag = true;
}
/**
 * 记录停止状态
 */
function logStop(i,j,k,pb,cb)
{
    ;
    console.log("停止记录，记录状态i="+i+",j="+j+",k="+k+"pb="+pb+",cb="+cb);
    window.curi = i;
    window.curj = j;
    window.curk = k;
    window.curpb = pb;
    window.curcb = cb;
}

/**
*async+await 百度的一个同步方法
*参数说明 
*i 当前省的序号
*j 当前市的序号
*k 当前区的序号
*pb  provinceBlocks 当前省一共多少个区
*cb cityBlocks 当前市一共多少个区
*蓝色字表示当前区域为低风险区域  可以自行修改
*红色的字表示高风险区域 可以自行修改
*/
(logLevel = async function (i,j,k,pb,cb){
	let finish = false;
	let provinces = $(".province li");
	let provincelength = provinces.length;
	let citylength = 0;
	let blocklength = 0;
	let curcity = null;
	let curblock = null;
	let curprovince = null;
	if(i<provinces.length)
	{
		if(k == 0)
		{
			provinces[i].click();
			//假休眠
			await sleepM();
		}
		curprovince = provinces[i].innerText;
		let citys = $(".city li");
		citylength = citys.length;
		
		if(j<citys.length)
		{
			if(k == 0)
			{
				citys[j].click();
				//假休眠
				await  sleepM();
			}
			curcity = citys[j].innerText;
			let blocks = $(".block li");
			blocklength = blocks.length;
			if(k<blocks.length)
			{
				curblock = blocks[k].innerText;
				blocks[k].click();
				await sleepM();
				
				
			}
			
		}
        let result = $(".level-result")[0].innerText;
		let level  =1; 
		if(result !="低风险地区")
		{
			level|=2;
		}
		if((level&2)>0&&result!="中风险地区")
		{
			level|=4;
		}
		/*是否输出低风险区域信息*/
		let showLowLevel = false;
		if(level==1&&showLowLevel)
		{
			console.log(curprovince+"省，"+curcity+"市，"+curblock+"区风险等级："+result);
		}
		//如果当前区域非低风险区域
		if((level&2)>0)
		{
			console.log("i="+i+",j="+j+",k="+k);
			console.log("%c"+curprovince+"省，"+curcity+"市，"+curblock+"区风险等级："+result,((level&4)>0?"color:red;":"color:blue;")+"font-weight:bold;");
		}
		k++;
		if(k>=blocklength)
		{
            cb = k;
            pb+=k;
			j ++;
			k = 0;
			console.log(curprovince+"省"+curcity+"市处理完成共"+cb+"个区");
			cb = 0;
		}
		if(j >= citylength)
		{
            
			i++;				
			k = 0;
			j = 0;
			console.log(curprovince+"省处理完成共"+pb+"个区");
			pb = 0;
		}
		if(window.stopflag)
        {       
            logStop(i,j,k,pb,cb);
        }
        else
        {
		    logLevel(i,j,k,pb,cb);
		}
	}
	else
	{
		console.log("处理完成");
	}
}

)()

logLevel(0,0,0,0,0)